/**
 * 2018年11月27日下午1:14:48
 * @author 谢进财
 */
package com.baihang.project.ds.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baihang.framework.dao.Record;
import com.baihang.framework.kit.JsonKit;
import com.baihang.framework.service.BaseService;
import com.baihang.project.ds.dao.TiShiDao;

import net.sf.json.JSONArray;

@Service
public class TiShiService extends BaseService {
	@Autowired
	private TiShiDao dao;
	
	public String getGrid(int page,int pagesize,String sortname,String sortorder) {
		int count = dao.queryForInt("select count(*) from room");
		
		List<Record> list = dao.queryForRecordList(String.format("select * from tips order by %s %s limit %d,%d ", sortname,sortorder,(page-1)*pagesize,pagesize));
		String jsonRecord = JsonKit.listToJson(list, 1);
		StringBuilder sb = new StringBuilder("{");
		sb.append("\"Rows\":"+jsonRecord+",");
		sb.append("\"Total\":"+count);
		sb.append("}");
		return sb.toString();
	}
	
	public boolean saveGrid(String json) {
		JSONArray jsonArray = JSONArray.fromObject(json); 
		dao.batchUpdateTiShiList(jsonArray);
		return true;
	}
	
}
